﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WSAP
{
    public partial class ModelVisible : Form
    {
        /// <summary>
        /// 三维绘图
        /// </summary>
        private StructrueChart chart3D { set; get; }

        /// <summary>
        /// 基础构造函数
        /// </summary>
        public ModelVisible()
        {
            InitializeComponent();

            #region 绘三维图时启用
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            //When this flag is set to true,
            //the control paints itself and is not painted by the system operation
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            //when set Control.DoubleBuffered to true, 
            //it will set the ControlStyles.AllPaintingInWmPaint and ControlStyles.OptimizedDoubleBuffer to true    
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            #endregion
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ModelVisible(WModelNet model, StructrueChartParam param) : this()
        {
            this.chart3D = new StructrueChart(model, this.PlotPanel, param);
            this.RefreshBackground();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ModelVisible(WSlabBuilderNet slab, SlabChartParam param) : this()
        {
            this.chart3D = new StructrueChart(slab, this.PlotPanel, param);
            this.trkElevation.Value = 90;
            this.trkAzimuth.Value = 0;
            this.RefreshBackground();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ModelVisible(WModelNet model) : this()
        {
            this.chart3D = new StructrueChart(model, this.PlotPanel);
            this.RefreshBackground();
        }

        /// <summary>
        /// 重新绘图，更新图片
        /// </summary>
        private void RefreshBackground()
        {
            if (this.chart3D == null) return;
            //绘图
            this.chart3D.ToGraphics(this.trkElevation.Value, this.trkAzimuth.Value);
        }

        /// <summary>
        /// 窗体大小改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PlotPanel_Resize(object sender, EventArgs e)
        {
            this.RefreshBackground();
        }

        /// <summary>
        /// 修改视高
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void trkElevation_Scroll(object sender, EventArgs e)
        {
            tbElevation.Text = trkElevation.Value.ToString();
            this.RefreshBackground();
        }

        /// <summary>
        /// 修改视角
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void trkAzimuth_Scroll(object sender, EventArgs e)
        {
            tbAzimuth.Text = trkAzimuth.Value.ToString();
            this.RefreshBackground();
        }
    }
}
